package com.leyou.gateway.config;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 虎哥
 */
@Data
@ConfigurationProperties("ly.filter")
public class FilterProperties {
    private List<String> allowPaths;
    private Map<String,String> allowPathMap = new HashMap<>();

    @PostConstruct
    public void init(){
        for (String allowPath : allowPaths) {
            String[] arr = StringUtils.split(allowPath, ":");
            if(arr.length != 2){
                throw new RuntimeException("登录拦截白名单路径的格式不正确！");
            }
            allowPathMap.put(arr[1], arr[0]);
        }
        System.out.println("allowPaths = " + allowPaths);
    }
}
